package com.zpark.controller;

import com.zpark.pojo.Empty;
import com.zpark.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/find")
    public ModelAndView findAll(){
        // 创建视图解析器
        ModelAndView mv = new ModelAndView();
        // 设置视图名字
        mv.setViewName("each");

        // 调用业务层获取数据
        List<Empty> emptys =  userService.findAllEmpty();

        // 绑定数据
        mv.addObject("lists", emptys);

        return mv;
    }

    @GetMapping("/empty")
    public  ModelAndView getEmpty(){
        // 创建视图解析器
        ModelAndView mv = new ModelAndView();
        // 设置视图名字
        mv.setViewName("demo02");

        //
       Empty  empty =  new Empty(10,"小红","188232344","男",1000.0,"贵阳");


        // 绑定数据
        mv.addObject("empty", empty);

        return mv;
    }

    @GetMapping("/map")
    public ModelAndView getEmptyMap(){
        // 创建视图解析器
        ModelAndView mv = new ModelAndView();
        // 设置视图名字
        mv.setViewName("map");

        // 创建empty对象
        Empty empty = new Empty(10, "张三", "123456789", "男", 1000.0, "贵阳");

        // 创建map对象
        Map<String, Object> map = new HashMap<>();
        map.put("empty", empty);
        map.put("con", "Hello Thymeleaf");

        // 调用业务层获取数据
        List<Empty> emptys =  userService.findAllEmpty();

        map.put("lists", emptys);


        // 绑定数据
        mv.addObject("maps", map);

        return mv;
    }

}
